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

__qualname__ and nested class naming fixes #1171

Merged
merged 2 commits into from
Nov 7, 2017

Conversation

jagerman
Copy link
Member

@jagerman jagerman commented Nov 6, 2017

A few fixes related to how we set __qualname__ and how we show the type name in function signatures (fixes #1166).

  • __qualname__ isn't supposed to have the module name at the beginning, but we've been putting it there. This removes it, while keeping the Nested.Class name chaining.

  • print __module__.__qualname__ rather than type->tp_name; the latter doesn't work properly for nested classes, so we would get module.B rather than module.A.B for a class B with parent A. This also unifies the Python 3 and PyPy code. Fixes Incorrect type names in docstrings for nested types #1166.

  • This now sets a __qualname__ attribute on the type (as would happen internally to Python 3.3+) for Python <3.3 and PyPy. While not particularly important to have in earlier Python versions, it's useful for us to be able to extracted the nested name for function signatures (which is why __qualname__ was invented in the first place).

  • Added tests for the above.

A few fixes related to how we set `__qualname__` and how we show the
type name in function signatures:

- `__qualname__` isn't supposed to have the module name at the
beginning, but we've been putting it there.  This removes it, while
keeping the `Nested.Class` name chaining.

- print `__module__.__qualname__` rather than `type->tp_name`; the
latter doesn't work properly for nested classes, so we would get
`module.B` rather than `module.A.B` for a class `B` with parent `A`.
This also unifies the Python 3 and PyPy code.  Fixes pybind#1166.

- This now sets a `__qualname__` attribute on the type (as would happen
in Python 3.3+) for Python <3.3, including PyPy.  While not particularly
important to have in earlier Python versions, it's useful for us to be
able to extracted the nested name, which is why `__qualname__` was
invented in the first place.

- Added tests for the above.
@wjakob
Copy link
Member

wjakob commented Nov 7, 2017

Looks like there is a minor warning on MSVC (use of two separate variables named "t" in nested scopes) that was treated as an error. Other than that, it looks great!

@jagerman jagerman merged commit 7117892 into pybind:master Nov 7, 2017
@jagerman jagerman added this to the v2.2.2 milestone Jan 12, 2018
jagerman added a commit to jagerman/pybind11 that referenced this pull request Jan 12, 2018
A few fixes related to how we set `__qualname__` and how we show the
type name in function signatures:

- `__qualname__` isn't supposed to have the module name at the
beginning, but we've been putting it there.  This removes it, while
keeping the `Nested.Class` name chaining.

- print `__module__.__qualname__` rather than `type->tp_name`; the
latter doesn't work properly for nested classes, so we would get
`module.B` rather than `module.A.B` for a class `B` with parent `A`.
This also unifies the Python 3 and PyPy code.  Fixes pybind#1166.

- This now sets a `__qualname__` attribute on the type (as would happen
in Python 3.3+) for Python <3.3, including PyPy.  While not particularly
important to have in earlier Python versions, it's useful for us to be
able to extracted the nested name, which is why `__qualname__` was
invented in the first place.

- Added tests for the above.
wjakob pushed a commit that referenced this pull request Feb 7, 2018
A few fixes related to how we set `__qualname__` and how we show the
type name in function signatures:

- `__qualname__` isn't supposed to have the module name at the
beginning, but we've been putting it there.  This removes it, while
keeping the `Nested.Class` name chaining.

- print `__module__.__qualname__` rather than `type->tp_name`; the
latter doesn't work properly for nested classes, so we would get
`module.B` rather than `module.A.B` for a class `B` with parent `A`.
This also unifies the Python 3 and PyPy code.  Fixes #1166.

- This now sets a `__qualname__` attribute on the type (as would happen
in Python 3.3+) for Python <3.3, including PyPy.  While not particularly
important to have in earlier Python versions, it's useful for us to be
able to extracted the nested name, which is why `__qualname__` was
invented in the first place.

- Added tests for the above.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect type names in docstrings for nested types
2 participants