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

Customizer rework #32

Closed
Thrameos opened this issue Jul 3, 2018 · 2 comments
Closed

Customizer rework #32

Thrameos opened this issue Jul 3, 2018 · 2 comments
Assignees

Comments

@Thrameos
Copy link
Owner

Thrameos commented Jul 3, 2018

The current customizer system works by adding or removing methods and base classes prior to the creation of the class. This is allowed to run arbitrary user code.

Limiting the types of actions to a fixed set of prescribed actions would make it much safer and ensure those actions take place consistently. It would also make it more future proof as the actions would be executed by the library code rather than by conventions.

@Thrameos
Copy link
Owner Author

Plan of attack for this is to use decorators so that the system is entirely automated rather than a customizer class.

from jpype import SuperFor, ImplementationFor, JClass

#Insert JString into the class tree as a base class of java.lang.String
@SuperFor("java.lang.String")
class JString(JObject):  # we must derive from JObject so that we will appear before it in the mro.
   # This method will appear in the class tree
   def doSomething(self):
      pass

# All methods from this class will be copied into java.lang.Object when that class is created.
@ImplementationFor("java.lang.Object")
class MyObjectMethods(object):
   # This method will appear in java.lang.Object class.  It can either be a static method 
   # which will take either the class or the object as self or a method which will expect
   # self to be an object.
   def doSomething(self):
      pass

To be resolved.

  • Will this work with the new style of decorator that is planned for python?
  • How to determine if it was called as a static method? Should be as easy as if isinstance(self, JClass): called static

@Thrameos Thrameos self-assigned this Jul 11, 2018
@Thrameos
Copy link
Owner Author

Completed in 0.7

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

1 participant