Comments (7)
After some discussion, the current proposal is:
(require-python 'module.class)
will makemodule.class
available in the calling*ns*
,- the default behavior of invoking
(module.class/method object ...)
will be the same asmodule.class.method(object, *args, **kwargs)
in Python (require-python '[module.class :coerce])
will make all calls that follow the pattern(module.class/method object ...)
coerce to($a method object)
to respect substitutionality OO principles(require-python '[module.class :strict])
will throw an error if a class method of classk
is called on a subclass ofk
calledk_sub
, then(module.k/method o)
would throw an exception if the appropriate invocation was(module.k_sub/method o)
(require/with-coercion (require-python ...))
will be made available in order to not have to explicitly specify:coerce
on every requirement,(require/with-strict ...)
will be made available for the same purpose,- classes will be loaded by default if
(require-python 'module)
or(require-python
[module ...])` syntax is employed, - modules will be loaded recursively so that if Python module
a
imports moduleb
, andb
importsc
, andc
has classd
, then you should expect to be able use(a.b.c/d ...)
and expect intellisense, metadata, and completion assistance.
from libpython-clj.
I want to type (mxnet.modules.Module/forward item batch-data) and have intellisense help me out.
Could you try (require-python '(mxnet mxnet.modules))
? I would expect that should let you do (mxnet.modules.Module/forward item batch-data)
.
from libpython-clj.
Regarding the rest, I'm going to suggest the following syntax, as I'm concerned getting overly clever with the require-python
syntax and implementation will come back to bite me (as there's no way to tell a priori in (require-python 'a.b)
if a
is a module and b
is a class in a
or if a.b
represents a module along a/b.py
).
This same problem is probably related to why Clojure solved this problem with import
, and I think maybe we could do the same trick. For instance:
(require-python '[builtins :as python])
(import-python '(python dict))
etc.
That would allow for more fine grained control without mucking stuff up too much.
On the other hand, it could be a lot more verbose. We could also potentially do
(require-python '[builtins :as python :import :all])
or
(require-python '[builtins :as python :import [(list :as pylist) dict])
which might be a little more concise
from libpython-clj.
On a little further consideration, I'm thinking:
(require-python '[builtins :as python :import [dict]])
will results in dict
being a namespace distinct from python
accessible by the current ns, whereas
(require-python '[builtins :as python :refer-classes :all])
and
(require-python '[builtins :as python :refer-classes [dict]])
will result in python.dict
being a namespace.
from libpython-clj.
On a little further consideration, I'm thinking:
(require-python '[builtins :as python :import [dict]])
will results in dict
being a namespace distinct from python
accessible by the current ns, whereas
(require-python '[builtins :as python :refer-classes :all])
and
(require-python '[builtins :as python :refer-classes [dict]])
will result in python.dict
being a namespace.
from libpython-clj.
The distinction between classes and modules seems oddly blurred to me. Why can I only require modules, which then end up as namespaces but I can't require classes, which also end up as namespaces?
The reason clojure has import is so you can have a type which you then use for things like type annotations and constructors. It specifically isn't used this way at all; if we are going to make namespaces out of python classes then I think that is a require, not an import.
It isn't always apparent when something is a submodule vs. when something is a class aside from capitalization. Classes have a constructor I guess and you could annotate their methods with an instanceof check maybe but we are blurring some lines here.
Basically, I feel that if you are creating a clojure namespace then you are doing a require pathway. If we statically code-gen these things then you would expect a normal require to work, not an import. So I would like the dynamic pathway to work the same as the code-gen pathway in most cases which means you need to be able to 'require' the class also and it can't be special syntax.
This actually makes me think that the :require-classes pathway in general and the :recurse pathway aren't necessary. If python-require worked with classes then you would just (require-python '[buildtins builtins.list])
and I think that is enough. What if we don't have the auto-method and just allow requiring directly of python classes?
from libpython-clj.
These have all been addressed
from libpython-clj.
Related Issues (20)
- Cannot run the example in the tutorial in Cider with JDK 17 HOT 8
- process hanging in embeded mode on exception HOT 2
- from-import does not support "string"
- newbie: I get: `dir already refers to: #'clojure.repl/dir in namespace: user` HOT 2
- Newbie: Lein Clojure Windows Anaconda VSCode Cava REPL Returns (NoClassDefFoundError) HOT 5
- Create Python Module then Import Module and Call Function Inside Clojure? HOT 4
- Fix ubuntu version in dockerfiles HOT 6
- Consider releasing returned values from instance fns
- JDK-20 support HOT 3
- builtins/eval throws 'frame does not exist' HOT 2
- Unable to require libraries from within docker using conda HOT 6
- Failed to find a valid python library on MS-Windows with the official python distributions
- Extend CI coverage to all the mainstream architectures
- require-python missing functions with annotation HOT 3
- Make polyglot development easier by allow require-python to be path-informed HOT 1
- Data transformation pipelines? HOT 1
- NSWindow main thread error when trying to setup Gymnasium (openapi gym) HOT 5
- JVM crashes when requiring `libpython-clj2.require` on 64bit Raspberry Pi 4 HOT 1
- error of unhashable type HOT 15
- Ways to reduce probability of memory leaks? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libpython-clj.