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

Expose module constants in traits.ctraits #688

Closed
wants to merge 7 commits into from

Conversation

rahulporuri
Copy link
Contributor

fixes #686

This PR exposes all of the module-level constants used in the traits.ctraits module. Exposing these constants will remove the need to duplicate the constants elsewhere in the traits codebase (This will be done in a separate PR).

Note that there are a new number of constants that need to be defined and exposed in traits.ctraits - which will also be done in a separate PR.

	modified:   traits/ctraits.c
	modified:   traits/tests/test_ctraits.py
@mdickinson
Copy link
Member

How does this interact with #680? (Disclaimer: I haven't looked at either PR yet.)

@codecov-io
Copy link

codecov-io commented Jan 2, 2020

Codecov Report

Merging #688 into master will increase coverage by 0.22%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #688      +/-   ##
==========================================
+ Coverage   69.43%   69.65%   +0.22%     
==========================================
  Files          40       40              
  Lines        6282     6282              
  Branches     1295     1295              
==========================================
+ Hits         4362     4376      +14     
+ Misses       1521     1504      -17     
- Partials      399      402       +3
Impacted Files Coverage Δ
traits/trait_types.py 66.33% <0%> (-0.17%) ⬇️
traits/traits.py 61.25% <0%> (+1.29%) ⬆️
traits/etsconfig/etsconfig.py 63.58% <0%> (+6.17%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 761d76d...807f61d. Read the comment docs.

@rahulporuri
Copy link
Contributor Author

How does this interact with #680? (Disclaimer: I haven't looked at either PR yet.)

This PR doesn't interact with #680 at all because I haven't updated the rest of traits to use these newly available constants from traits.ctraits. But i do hope that once this and the upcoming PR get merged, #680 can rely on these module constants instead of redefining them.

@mdickinson mdickinson self-requested a review January 3, 2020 10:16
@mdickinson mdickinson added this to the 6.0.0 release milestone Jan 3, 2020
traits/ctraits.c Outdated Show resolved Hide resolved
Copy link
Member

@mdickinson mdickinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOKTM, but needs merge conflicts resolved and error handling added.

There are a couple of promised follow-on PRs; this PR won't really make much sense without them. @rahulporuri How would you feel about expanding this PR to include the uses of the constants. Otherwise, we end up with duplication in master, and there's a risk that we don't get around to the later PRs.

traits/ctraits.c Outdated Show resolved Hide resolved
rahul poruri added 6 commits January 6, 2020 14:01
	modified:   traits/ctraits.c
	modified:   traits/tests/test_ctraits.py
	modified:   traits/constants.py
	modified:   traits/tests/test_ctraits.py
	modified:   traits/ctraits.c
	modified:   traits/tests/test_ctraits.py
	modified:   traits/ctraits.c
@@ -10,6 +10,19 @@

from enum import IntEnum

from traits.ctraits import (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduces a circular import: traits.trait_base imports from traits.constants, which imports from traits.ctraits, which imports from traits.trait_base. The solution may be to lift CoercableTypes to trait_handlers, which is the only place that it's used.

Copy link
Contributor

@corranwebster corranwebster Jan 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or perhaps put Undefined and Uninitialized somewhere other than in trait_base? No, moving CoercableTypes is better.

@@ -4908,6 +4908,46 @@ PyMODINIT_FUNC PyInit_ctraits(void) {
(PyObject *) &trait_type ) < 0 )
return NULL;

/* Default value type constants */
if ( PyModule_AddIntConstant(
Copy link
Member

@mdickinson mdickinson Jan 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not especially keen on the assign-and-test style, in general. I think it would be more readable to separate the assignment from the error check. Also, let's follow PEP 7 in new code, and always use braces, even for single-statement blocks.

err = PyModule_AddIntConstant(module, "_CONSTANT_DEFAULT_VALUE", CONSTANT_DEFAULT_VALUE);
if (err) {
    return NULL;
}

@mdickinson
Copy link
Member

@rahulporuri Any idea when you might be able to get to the updates on this PR?

@rahulporuri
Copy link
Contributor Author

@rahulporuri Any idea when you might be able to get to the updates on this PR?

I don't think I will be able to work on this PR anytime soon (~ 2 weeks)

@mdickinson mdickinson assigned mdickinson and unassigned rahulporuri Jan 20, 2020
@mdickinson
Copy link
Member

Okay. I'll try to pick this up at some point.

@mdickinson
Copy link
Member

Deferring this; it's not essential for 6.0, and there's no user-facing behaviour change.

@mdickinson mdickinson removed their assignment Mar 11, 2020

#: A new instance of TraitListObject constructed using the default_value list
#: is the default value.
trait_list_object = 5
trait_list_object = _TRAIT_LIST_COPY_DEFAULT_VALUE
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming nitpick: we probably want _TRAIT_LIST_OBJECT_DEFAULT_VALUE (and similarly for trait_dict_object)

@mdickinson
Copy link
Member

Closing in favour of #935.

@mdickinson mdickinson closed this Mar 16, 2020
@mdickinson mdickinson deleted the feat/expose-module-constants-ctraits branch March 16, 2020 10:52
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.

Proposal : Expose int constants in the traits.ctraits module
4 participants