New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Button title should only be passed if the method accepts arguments #335

Closed
mpmc opened this Issue Jan 4, 2018 · 6 comments

Comments

Projects
None yet
2 participants
@mpmc
Contributor

mpmc commented Jan 4, 2018

Say I have a button, this button calls method foo..

def foo():
    print('I was called!')

Because the button title is always passed, but the foo function doesn't accept any - you get..

TypeError: foo() takes 0 positional arguments but 1 was given

The obvious solution to this would be to handle this in the foo method like so.

def foo(button=None):
    print('I was called!')

or

def foo(*args, **kwargs):
    print('I was called!')

While this works, the problem is that many analysers complain if an arg is passed but not used. An example of this is shown here

@jarvisteach

This comment has been minimized.

Owner

jarvisteach commented Jan 4, 2018

Some ideas here: https://stackoverflow.com/questions/847936/how-can-i-find-the-number-of-arguments-of-a-python-function

In MAKE_FUNC funcName could be inspected, and if it receives no parameters, then we could pass None...

@jarvisteach jarvisteach added this to the 1.0 milestone Jan 4, 2018

jarvisteach added a commit that referenced this issue Jan 9, 2018

functions can be defined with no parameter #335
It’s now possible to configure functions to not receive an argument
(for example the buttons name). Simply don’t include a parameter in the
function definition and appJar can handle it :)
@jarvisteach

This comment has been minimized.

Owner

jarvisteach commented Jan 9, 2018

This is now possible, and in fact affects all widgets that specify a function.

Now, if a function has no parameters, no arguments will be passed...

@jarvisteach jarvisteach closed this Jan 9, 2018

jarvisteach added a commit that referenced this issue Jan 16, 2018

Update #335
MAKE_FUNCTION will now discard arguments, when no parameters

@jarvisteach jarvisteach reopened this Feb 14, 2018

@jarvisteach

This comment has been minimized.

Owner

jarvisteach commented Feb 14, 2018

There's an issue with this...

  • If a function being referenced is part of a class, then it will have a parameter - self.
  • The inspection didn't take this into account.
    • If it sees no args, then no parameter is passed
    • If it sees an arg, then the parameter is passed - so if the arg was self (required when building a class) things broke down.

For now, I will assume that if a variable is called self we treat it as not being present, and don't pass an argument.

However, users might not call the object parameter self, so this isn't a bulletproof solution. Can we inspect the function to determine if it is part of a class?

@jarvisteach

This comment has been minimized.

Owner

jarvisteach commented Feb 14, 2018

A bit of googling reveals: inspect.ismethod(object) which returns True of the function is bound to a class, and will therefore contain a self parameter.

jarvisteach added a commit that referenced this issue Feb 14, 2018

Update to MAKE_FUNC
MAKE_FUNC now handles class functions #335
Renamed access widget buttons #328
@jarvisteach

This comment has been minimized.

Owner

jarvisteach commented Feb 14, 2018

Seems to do the trick.

Also, got rid of the need to specify discard parameters, args* will handle 0 or more parameters, so can set it to always discard.

Will need to go through and remove all references, and test them...

jarvisteach added a commit that referenced this issue Mar 3, 2018

Update MAKE_FUNC calling #335
Removing discard parameter from calls to MAKE_FUNC

Some changes to:
* fullScreen - better handles different arguments
* DatePicker - better handles no arguments

jarvisteach added a commit that referenced this issue Mar 3, 2018

Update MAKE_FUNC calling #335
All references removed.
@jarvisteach

This comment has been minimized.

Owner

jarvisteach commented Mar 3, 2018

The discard parameter has now been removed.

@jarvisteach jarvisteach closed this Mar 3, 2018

jarvisteach added a commit that referenced this issue Mar 3, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment