Skip to content
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

fix tab-completion for methods injected by MorphismMethods #29776

Closed
mwageringel opened this issue Jun 1, 2020 · 9 comments
Closed

fix tab-completion for methods injected by MorphismMethods #29776

mwageringel opened this issue Jun 1, 2020 · 9 comments

Comments

@mwageringel
Copy link

For Cython classes that implement morphisms, the methods from MorphismMethods of the respective category are magically attached to elements of the class. However, tab-completion does not work on them.

For example, sage.categories.rings defines the morphism methods extend_to_fraction_field and is_injective:

sage: R.<x,y> = QQ[]
sage: f = R.hom([x, y+1], R)
sage: f.extend_to_frac<TAB>  # should complete to f.extend_to_fraction_field
sage: f.is_injec<TAB>  # should complete to f.is_injective

This is fixed by improving the corresponding __dir__ method.

Component: categories

Author: Markus Wageringel

Branch/Commit: 23cf6e7

Reviewer: Travis Scrimshaw

Issue created by migration from https://trac.sagemath.org/ticket/29776

@mwageringel mwageringel added this to the sage-9.2 milestone Jun 1, 2020
@mwageringel
Copy link
Author

Branch: u/gh-mwageringel/29776

@mwageringel
Copy link
Author

Author: Markus Wageringel

@mwageringel
Copy link
Author

Commit: 23cf6e7

@mwageringel
Copy link
Author

New commits:

23cf6e729776: fix tab-completion for morphism methods

@tscrim
Copy link
Collaborator

tscrim commented Jun 2, 2020

comment:2

Does the affect the method lookup time (the time it takes to call the methods) when the code is being run? For example, does it make something like 3.divides(9) slower?

@mwageringel
Copy link
Author

comment:3

Method lookup does not actually call __dir__, which would be inefficient as __dir__ returns a list. In fact, I am not sure if it is used for anything but tab-completion. The Python documentation says that

*[...] dir() is supplied primarily as a convenience for use at an interactive prompt [...]*

@tscrim
Copy link
Collaborator

tscrim commented Jun 2, 2020

Reviewer: Travis Scrimshaw

@tscrim
Copy link
Collaborator

tscrim commented Jun 2, 2020

comment:4

Thanks. I couldn't find any information if that was used during method lookup (cf. __getattr__, __getattribute__). That gave me an idea to test, and the __dir__ is indeed only called on tab completion. Which also makes sense given its return type. Sorry for the dumb question. LGTM.

@vbraun
Copy link
Member

vbraun commented Jun 5, 2020

Changed branch from u/gh-mwageringel/29776 to 23cf6e7

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

No branches or pull requests

3 participants