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

Map._extra_slots(): do not pass dict #24372

Closed
jdemeyer opened this issue Dec 13, 2017 · 11 comments
Closed

Map._extra_slots(): do not pass dict #24372

jdemeyer opened this issue Dec 13, 2017 · 11 comments

Comments

@jdemeyer
Copy link

In the Map method _extra_slots, a dict is passed as input. That dict is then modified in-place and also returned as output.

This awkward logic is not needed for anything. We simplify this by not passing a dict as input and creating a new dict from scratch if needed.

Component: coercion

Author: Jeroen Demeyer

Branch/Commit: 375e40f

Reviewer: Travis Scrimshaw

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

@jdemeyer jdemeyer added this to the sage-8.2 milestone Dec 13, 2017
@jdemeyer
Copy link
Author

Branch: u/jdemeyer/ticket/24372

@jdemeyer
Copy link
Author

New commits:

375e40fMap._extra_slots(): do not pass dict

@jdemeyer
Copy link
Author

Commit: 375e40f

@tscrim
Copy link
Collaborator

tscrim commented Dec 15, 2017

comment:3

LGTM overall, but I do not feel 100% comfortable relying on an uninitialized zero_element being None by default:

        if self.zero_element is None:
            self.zero_element = self._codomain.zero()

So I would add self.zero_element = None in the __init__.

Probably we should also add the other cdef classes (such as Z_to_quadratic_field_element) to the .pxd file, but that can be done on a followup.

@jdemeyer
Copy link
Author

comment:4

Interestingly, http://cython.readthedocs.io/en/latest/src/userguide/special_methods.html#initialisation-methods-cinit-and-init says

"Any Python attributes have also been initialised to None, but you probably shouldn’t rely on that."

@tscrim
Copy link
Collaborator

tscrim commented Dec 16, 2017

comment:5

So are you saying we should just leave it be?

@jdemeyer
Copy link
Author

comment:6

Replying to @tscrim:

So are you saying we should just leave it be?

I just sent an email to the Cython mailing list to ask for clarification.

@jdemeyer
Copy link
Author

comment:7

Reply from a Cython developer:

As long as Cython controls the type hierarchy, you can rely on it. Exposing
NULL values for Python attributes to !Python/Cython code would be unhelpful.

There is one exception: when __cinit__() is called, attributes that are
defined by subtypes have not been initialised yet and thus are still NULL
instead of None.

In short: what I did is correct.

@tscrim
Copy link
Collaborator

tscrim commented Dec 18, 2017

Reviewer: Travis Scrimshaw

@tscrim
Copy link
Collaborator

tscrim commented Dec 18, 2017

comment:8

Alright, then positive review.

@vbraun
Copy link
Member

vbraun commented Dec 22, 2017

Changed branch from u/jdemeyer/ticket/24372 to 375e40f

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