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

Package implementation using Replace exception have corner cases. #241

Closed
proofit404 opened this issue Apr 1, 2020 · 1 comment · Fixed by #504
Closed

Package implementation using Replace exception have corner cases. #241

proofit404 opened this issue Apr 1, 2020 · 1 comment · Fixed by #504
Labels

Comments

@proofit404
Copy link
Owner

proofit404 commented Apr 1, 2020

Injector:

            if set(args).issubset(cached):
                kwargs = {k: cache[k] for k in args if k in cache}

                try:
                    cache[current_attr] = attribute(**kwargs)
                except Replace as replace:
                    deep_replace_dependency(cls, current_attr, replace)
                    # FIXME:
                    #
                    # We'll probably resolve weakref.  This happens because nested
                    # injector decide to replace a lazy import.  This nested injector
                    # is already resolved by its parent, so it contain a weakref in
                    # it.  Ideally we should not have parent in the scope at all.
                    #
                    # Also, `Replace` doesn't change dependencies dict of its parent,
                    # so lazy import will be evaluated again and again.  This kills
                    # the whole point of `Replace`.
                    check_loops(cls.__name__, cls.__dependencies__)
                    check_circles(cls.__dependencies__)
                    continue

Loops check:

    elif attrname == "__parent__":
        from weakref import ReferenceType

        if isinstance(spec[1], ReferenceType):
            # FIXME: This is an ad-hoc solution for the broken
            # `Replace` problem.  See `dependencies._injector` comment
            # for more info.
            resolved_parent = spec[1]().__dependencies__
        else:
            resolved_parent = spec[1]
        check_loops_for(class_name, attribute_name, resolved_parent, origin, expression)
@proofit404 proofit404 added the bug label Apr 1, 2020
@proofit404 proofit404 added this to the Package object. milestone Feb 12, 2021
@proofit404
Copy link
Owner Author

Replace exception could be reused with generator based recursive function in the graph module.

See analyze module for example.

proofit404 added a commit that referenced this issue Jul 6, 2021
Package lazy loading was one via hot replacement parts of the graph
during dependency injection process.  At that moment we decide to
initialize dependency graph on first injection, so package lazy
import will be a side effect of dependency lazy initialization.
@proofit404 proofit404 linked a pull request Jul 6, 2021 that will close this issue
proofit404 added a commit that referenced this issue Jul 6, 2021
Package lazy loading was one via hot replacement parts of the graph
during dependency injection process.  At that moment we decide to
initialize dependency graph on first injection, so package lazy
import will be a side effect of dependency lazy initialization.
proofit404 added a commit that referenced this issue Jul 6, 2021
Package lazy loading was one via hot replacement parts of the graph
during dependency injection process.  At that moment we decide to
initialize dependency graph on first injection, so package lazy
import will be a side effect of dependency lazy initialization.
proofit404 added a commit that referenced this issue Jul 6, 2021
Package lazy loading was one via hot replacement parts of the graph
during dependency injection process.  At that moment we decide to
initialize dependency graph on first injection, so package lazy
import will be a side effect of dependency lazy initialization.
proofit404 added a commit that referenced this issue Jul 6, 2021
Package lazy loading was one via hot replacement parts of the graph
during dependency injection process.  At that moment we decide to
initialize dependency graph on first injection, so package lazy
import will be a side effect of dependency lazy initialization.
proofit404 pushed a commit that referenced this issue Jul 6, 2021
# [7.0.0-rc.2](7.0.0-rc.1...7.0.0-rc.2) (2021-07-06)

### Bug Fixes

* initialize dependency graph lazily [#241](#241) ([4d0d3c9](4d0d3c9))
proofit404 added a commit that referenced this issue Jul 21, 2021
Package lazy loading was one via hot replacement parts of the graph
during dependency injection process.  At that moment we decide to
initialize dependency graph on first injection, so package lazy
import will be a side effect of dependency lazy initialization.
proofit404 added a commit that referenced this issue Jul 21, 2021
Package lazy loading was one via hot replacement parts of the graph
during dependency injection process.  At that moment we decide to
initialize dependency graph on first injection, so package lazy
import will be a side effect of dependency lazy initialization.
proofit404 pushed a commit that referenced this issue Jul 21, 2021
# [7.0.0](6.0.1...7.0.0) (2021-07-21)

### Bug Fixes

* hide scope objects own attributes [#514](#514) ([1af2173](1af2173))
* initialize dependency graph lazily [#241](#241) ([1e18e74](1e18e74))
* store nested injector spec as scalar data type [#510](#510) ([2344892](2344892))

### Features

* deny classes to depend on nested injectors [#479](#479) ([dafdf85](dafdf85))
* deny resolve nested injector directly [#474](#474) ([6a4d86d](6a4d86d))
* deny resolve this objects directly [#472](#472) ([9786dbd](9786dbd))
* deny to resolve value object directly [#473](#473) ([bece3d1](bece3d1))
* respect resolution ruses in package objects [#471](#471) ([db9b790](db9b790))
* scalar dependencies can't be resolved directly [#480](#480) ([591c605](591c605))

### BREAKING CHANGES

* Injector won't pass nested injectors to the constructor
of the class. Use `this` objects to access inner attributes of nested
injector and pass them to the constructor arguments.
* The only allowed purpose of nested injectors is
to be targets for this objects.
* Package objects will conform its resolution
rules with imported objects.  If package dependency points
to the class, it's allowed to resolve such dependency directly.
If package object points to the scalar type for example,
it'll raise exception if you tries to resolve such dependency
directly.
* The only allowed purpose of this objects is
to specify dependencies of classes and value objects as links
to attributes with different names or stored in nested Injector
classes.
* value objects could only be used to evaluate
arguments of classes. Attribute access of Injector subclass
which result in value object would raise an error.
* Scalar dependencies are basically data types.
They are allowed to be used as dependencies for other more
complicated data types, like classes. If you need to take
scalar dependency from Injector subclass, use constant value
instead. You don't need Injector for this.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant