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

Made module_local types take precedence over global types #981

Merged
merged 1 commit into from
Aug 5, 2017

Conversation

jagerman
Copy link
Member

@jagerman jagerman commented Aug 4, 2017

Attempting to mix py::module_local and non-module_local classes results
in some unexpected/undesirable behaviour:

  • if a class is registered non-local by some other module, a later
    attempt to register it locally fails. It doesn't need to: it is
    perfectly acceptable for the local registration to simply override
    the external global registration.
  • going the other way (i.e. module A registers a type T locally,
    then B registers the same type T globally) causes a more serious
    issue: A.T's constructors no longer work because the self argument
    gets converted to a B.T, which then fails to resolve.

Changing the cast precedence to prefer local over global fixes this and
makes it work more consistently, regardless of module load order.

Attempting to mix py::module_local and non-module_local classes results
in some unexpected/undesirable behaviour:

- if a class is registered non-local by some other module, a later
  attempt to register it locally fails.  It doesn't need to: it is
  perfectly acceptable for the local registration to simply override
  the external global registration.
- going the other way (i.e. module `A` registers a type `T` locally,
  then `B` registers the same type `T` globally) causes a more serious
  issue: `A.T`'s constructors no longer work because the `self` argument
  gets converted to a `B.T`, which then fails to resolve.

Changing the cast precedence to prefer local over global fixes this and
makes it work more consistently, regardless of module load order.
@jagerman jagerman merged commit 4b15923 into pybind:master Aug 5, 2017
@dean0x7d dean0x7d modified the milestone: v2.2 Aug 13, 2017
@jagerman jagerman deleted the module-local-precedence branch August 14, 2017 20:25
@rwgk rwgk mentioned this pull request Feb 9, 2023
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.

None yet

2 participants