Skip to content

Commit

Permalink
Auto-adjust operator __qualname__
Browse files Browse the repository at this point in the history
  • Loading branch information
lukelbd authored and Try2Code committed Mar 29, 2023
1 parent b39e8ad commit 6b49cd9
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions python/cdo.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def __get__(self, instance, owner):
# called with 'cdo.for()' because 'for' is a keyword in python. 'for' is
# renamed to 'seq' in 1.9.7.
# This workaround translates all calls of 'seq' into for in case of
# versions prior tp 1.9.7
# versions prior to 1.9.7
if name in self.AliasOperators.keys() and \
(parse_version(getCdoVersion(self.CDO)) < parse_version('1.9.7')):
name = self.AliasOperators[name]
Expand Down Expand Up @@ -324,9 +324,9 @@ def __call(self, cmd, envOfCall={}):

if self.debug: # debug printing {{{
print('# DEBUG - start =============================================================')
# if {} != env:
# for k,v in list(env.items()):
# print("ENV: " + k + " = " + v)
# if {} != env:
# for k,v in list(env.items()):
# print("ENV: " + k + " = " + v)
print('CALL :' + ' '.join(cmd))
print('STDOUT:')
if (0 != len(stdout.strip())):
Expand Down Expand Up @@ -551,7 +551,11 @@ def __getattr__(self, method_name): # main method-call handling for Cdo-objects

# cache the method for later
class Operator(self.__class__):
name = __name__ = method_name
name = method_name
__name__ = method_name
__qualname__ = getattr( # __qualname__ is available in python 3.3+
self.__class__, '__qualname__', self.__class__.__name__
) + '.' + method_name

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand All @@ -563,7 +567,7 @@ def __init__(self, *args, **kwargs):
# given method might match part of know operators: autocompletion
func = lambda x: re.search(method_name, x)
options = list(filter(func, self.operators.keys()))
message = "Unknown method '" + method_name + "'!"
message = "Unknown operator '" + method_name + "'!"
if 0 != len(options):
message += " Did you mean: " + ", ".join(options) + "?"
raise AttributeError(message)
Expand Down

0 comments on commit 6b49cd9

Please sign in to comment.