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

Stop polluting builtins from PythonUtil. #1256

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Maxwell175
Copy link
Contributor

Issue description

This PR prevents PythonUtil from polluting the builtins with it's classes and functions.
Polluting builtins can cause many unintended bugs or oddities and is considered bad practice.

Solution description

This PR removes the section in PythonUtil that adds all the functions and classes to builtins.
No utilities are being removed in this PR.
If you would like to use one of these classes, you would simply need to import them.

Checklist

I have done my best to ensure that…

  • …I have familiarized myself with the CONTRIBUTING.md file
  • …this change follows the coding style and design patterns of the codebase
  • …I own the intellectual property rights to this code
  • …the intent of this change is clearly explained
  • …existing uses of the Panda3D API are not broken
  • …the changed code is adequately covered by the test suite, where possible.

@codecov
Copy link

codecov bot commented Feb 2, 2022

Codecov Report

Merging #1256 (cf12046) into master (f0b81d5) will decrease coverage by 0.78%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1256      +/-   ##
==========================================
- Coverage   16.92%   16.14%   -0.79%     
==========================================
  Files        3632     3744     +112     
  Lines      340864   362805   +21941     
==========================================
+ Hits        57694    58571     +877     
- Misses     283170   304234   +21064     
Impacted Files Coverage Δ
direct/src/showbase/PythonUtil.py 27.19% <ø> (-2.09%) ⬇️
panda/src/putil/copyOnWriteObject.I 72.22% <0.00%> (-16.42%) ⬇️
panda/src/pipeline/reMutexDirect.I 49.20% <0.00%> (-15.38%) ⬇️
dtool/src/dtoolbase/deletedChain.T 91.66% <0.00%> (-8.34%) ⬇️
...anda/src/putil/cachedTypedWritableReferenceCount.I 68.35% <0.00%> (-7.71%) ⬇️
panda/src/linmath/lvecBase4_src.I 43.24% <0.00%> (-6.76%) ⬇️
panda/src/linmath/lvecBase3_src.I 46.13% <0.00%> (-5.97%) ⬇️
panda/src/pgraph/renderState.I 40.11% <0.00%> (-4.69%) ⬇️
panda/src/express/nodeReferenceCount.I 75.00% <0.00%> (-4.69%) ⬇️
panda/src/putil/nodeCachedReferenceCount.I 59.15% <0.00%> (-3.54%) ⬇️
... and 216 more

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 f0b81d5...cf12046. Read the comment docs.

@Moguri
Copy link
Collaborator

Moguri commented May 9, 2022

While I agree with the spirit of the changes, this looks like an API-breaking change.

@loblao
Copy link
Contributor

loblao commented May 9, 2022

Messing with PythonUtil is guaranteed to upset those guys maintaining old Disney games. Though, given that it has happened a couple of times, I suspect they have stopped relying on PythonUtil by now, but who knows.

IIRC getBase() and getRepository(), for example, are used all over the code as builtins. TIL they are defined in PythonUtil.

If anything, I'd recommend removing the most obscure ones first.

@Maxwell175
Copy link
Contributor Author

Maxwell175 commented May 9, 2022

Yeah, I think that the overall health of panda3d is more important. Polluting builtins with commonly used names is a recipe for bugs.

@loblao Once again this PR does not remove anything. if anyone really wants to keep using their builtins they can add them manually in their own code, Or, you know, just from direct.showbase.PythonUtil import * or something of the sort. it is very trivial to workaround and it would improve panda3d code health.

Also this is proposed for Panda3D 1.11, which is exactly the place for breaking changes. @Moguri

@Moguri
Copy link
Collaborator

Moguri commented Jun 10, 2022

1.11 is not the place for breaking changes. Breaking changes should only occur in a major version bump (e.g., 2.0).

However, I agree that some of those names are problematic and ripe for unexpected name collisions. I do not know @rdb's opinion on the matter, but I would prefer we at least move these builtin assignments to a new module so the behavior can be restored with one line of code (importing the new module).

@Maxwell175
Copy link
Contributor Author

1.11 is not the place for breaking changes. Breaking changes should only occur in a major version bump (e.g., 2.0).

This is by no means a documented API and there have been plenty of much more significant changes between say 1.9 and 1.10.

[...] so the behavior can be restored with one line of code (importing the new module).

builtins.__dict__.update(__import__('direct.showbase.PythonUtil', fromlist=['*']).__dict__)

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

3 participants